package com.example.administrator.financialmanager;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.Toast
        ;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class HomeActivity extends AppCompatActivity {
    ImageView home_add_outcome;
    ImageView home_add_income;
    ImageView home_my_outcome;
    ImageView home_my_income;
    ImageView home_manage_data;
    ImageView home_setting_system;
    ImageView home_io_note;
    ImageView home_help;
    ImageView home_exit_user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        //获取各个组件
        home_add_outcome = findViewById(R.id.home_add_outcome);
        home_add_income = findViewById(R.id.home_add_income);
        home_my_outcome = findViewById(R.id.home_my_outcome);
        home_my_income = findViewById(R.id.home_my_income);
        home_manage_data = findViewById(R.id.home_manage_data);
        home_setting_system = findViewById(R.id.home_setting_system);
        home_io_note = findViewById(R.id.home_io_note);
        home_help = findViewById(R.id.home_help);
        home_exit_user = findViewById(R.id.home_exit_user);

        //给各个组件添加监听
        home_add_outcome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, AddOutcomeActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });
        home_add_income.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, AddIncomeActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });
        home_my_outcome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, OutcomeListActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });
        home_my_income.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, IncomeListActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });
        home_manage_data.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, DataManageHomeActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });
        home_setting_system.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, SystemSettingActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });
        home_io_note.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, AddFlagActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });

        home_help.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HomeActivity.this, HelpActivity.class);// 使用AddOutaccount窗口初始化Intent
                startActivity(intent);// 打开AddOutaccount
            }
        });
        home_exit_user.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

//    GridView gridView;
//    SimpleAdapter sim_adapter;
//    List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
//
//    String[] names = new String[]{"新增支出", "新增收入", "我的支出", "我的收入",
//            "数据管理","系统设置", "收支便签", "帮助","退出"};
//    int[] images = new int[]{R.drawable.outcome01, R.drawable.income01, R.drawable.outcome_state01,
//            R.drawable.income_state01, R.drawable.date_manage01, R.drawable.setting01,
//            R.drawable.note01, R.drawable.help01, R.drawable.exit01};
//
//
//    void insert() {
//        for (int i = 0; i <names.length ; i++) {
//            Map<String, Object> map = new HashMap<String, Object>();
//            map.put("image", images[i]);
//            map.put("text", names[i]);
//            list.add(map);
//        }
//    }


//        gridView = (GridView) findViewById(R.id.home_function_grid);
//        String [] from ={"image","text"};
//        int [] to = {R.id.image,R.id.text};
//        sim_adapter = new SimpleAdapter(this, list, R.layout.item, from, to);
//        gridView.setAdapter(sim_adapter);

//        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {// 为GridView设置项单击事件
//            @Override
//            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
//                                    long arg3) {
//                Intent intent = null;// 创建Intent对象
//                switch (arg2) {
//                    case 0:
//                        Toast.makeText(HomeActivity.this, "您点了第1个图标",
//                                Toast.LENGTH_SHORT).show();
//                        break;
//                    case 1:
//                        Toast.makeText(HomeActivity.this, "您点了第2个图标",
//                                Toast.LENGTH_SHORT).show();
//                        break;

//                    case 0:
//                        intent = new Intent(HomeActivity.this, AddOutaccount.class);// 使用AddOutaccount窗口初始化Intent
//                        startActivity(intent;// 打开AddOutaccount
//                        break;
//                    case 1:
//                        intent = new Intent(HomeActivity.this, AddInaccount.class);// 使用AddInaccount窗口初始化Intent
//                        startActivity(intent);// 打开AddInaccount
//                        break;
//                    case 2:
//                        intent = new Intent(HomeActivity.this, Outaccountinfo.class);// 使用Outaccountinfo窗口初始化Intent
//                        startActivity(intent);// 打开Outaccountinfo
//                        break;
//                    case 3:
//                        intent = new Intent(HomeActivity.this, Inaccountinfo.class);// 使用Inaccountinfo窗口初始化Intent
//                        startActivity(intent);// 打开Inaccountinfo
//                        break;
//                    case 4:
//                        intent = new Intent(HomeActivity.this, Showinfo.class);// 使用Showinfo窗口初始化Intent
//                        startActivity(intent);// 打开Showinfo
//                        break;
//                    case 5:
//                        intent = new Intent(HomeActivity.this, Sysset.class);// 使用Sysset窗口初始化Intent
//                        startActivity(intent);// 打开Sysset
//                        break;
//                    case 6:
//                        intent = new Intent(HomeActivity.this, Accountflag.class);// 使用Accountflag窗口初始化Intent
//                        startActivity(intent);// 打开Accountflag
//                        break;
//                    case 7:
//                        intent = new Intent(HomeActivity.this, Help.class);// 使用Help窗口初始化Intent
//                        startActivity(intent);// 打开Help
//                        break;
//                    case 8:
//                        finish();// 关闭当前Activity
//                }
//            }
//        });

}
